<template>
	<div class="explore">
		<view class="nav-header-title">
			<view class="nav-title">
				探索
			</view>
		</view>

		<view class="section-box">
			<view class="top-title">
				<view class="title-left">主题</view>
				<view class="title-right" @click="lookTopicAll">查看全部</view>
			</view>

			<view class="ul-topic">
				<block v-for="item in topicList" :key="'t'+item.id">
					<view class="li-topic" @click="goTopic(item.title)">
						<view class="topic-img">
							<image :src="item.url" mode="aspectFill"></image>
						</view>
						<view class="topic-desc">
							<view class="desc-title">{{item.title}}</view>
							<view class="desc-exp">{{item.num}}+ 文章</view>
						</view>
					</view>
				</block>
			</view>

			<view class="top-title">
				<view class="title-left">热门话题</view>
				<!-- <view class="title-right">查看全部</view> -->
			</view>

			<view class="trending-list">
				<block v-for="item in exploreList" :key="item.id">
					<view class="news-box" @click="goDetail(item.id)">
						<view class="news-img">
							<image v-if="/.*thepaper.*/gi.test(item.head_img)"
								:src="`https://images.weserv.nl/?url=${item.head_img}`" mode="aspectFill"></image>
							<image v-else :src="`${item.head_img}`" mode="aspectFill"></image>
						</view>
						<view class="news-writing">
							<view class="p-location">{{item.tag}}</view>
							<view class="p-title">{{item.title}}</view>
							<view class="p-come">
								<view class="p-come-left">
									<view class="p-person">
										<text class="person-icon">
											<image :src="item.user_avators" mode=""></image>
										</text>
										<text class="person">{{item.media}}</text>
									</view>
									<view class="p-time">{{item.publish_time}}</view>
								</view>
								<view class="p-come-right">
									<!-- <text class="come-right-icon"></text> -->
								</view>
							</view>
						</view>
					</view>
				</block>
			</view>
		</view>
	</div>
</template>

<script>
	import {
		getNews
	} from "@/api/request"
	export default {
		data() {
			return {
				exploreList: [],
				topicList: [{
						id: 0,
						title: "时事",
						url: "../../static/image/newstype/ss.jpg",
						num: "19k"
					},
					{
						id: 1,
						title: "财经",
						url: "../../static/image/newstype/cj.jpg",
						num: "12k"
					},
					{
						id: 2,
						title: "思想",
						url: "../../static/image/newstype/sx.jpg",
						num: "3000"
					}
				],

			}
		},
		methods: {
			lookTopicAll(){
				uni.navigateTo({
					url:"/pages/search/search?index=1"
				})
			},
			//去主题列表
			goTopic(title){
				uni.navigateTo({
					url:"/pages/topic/topic?type=" + title
				})
			},
			//去详情页
			goDetail(id) {
				console.log(id);
				uni.navigateTo({
					url: "/pages/detail/detail?id=" + id
				})
			},
			getIndexNews() {
				let data = {}
				getNews(data).then(content => {
					// console.log("首页列表数据==>", content);
					let {
						code,
						data
					} = content
					if (code == 200) {
						this.exploreList = data
					}
				})
			}
		},
		onLoad() {
			this.getIndexNews();
		}
	}
</script>

<style lang="scss" scoped>
	.explore {
		position: relative;
		width: 100%;
		padding: 0 $uni-box-padding;
	}

	.nav-header-title {
		z-index: 1;
		position: fixed;
		top: 0;
		left: 0;
		padding: 30rpx 30rpx;
		width: 100%;
		background-color: #fff;

		.nav-title {
			font-size: 48rpx;
			font-weight: bold;
			color: #000;
		}
	}

	.section-box {
		width: 100%;
		padding-top: 120rpx;

		.top-title {
			padding-bottom: 20rpx;
			width: 100%;
			display: flex;
			align-items: center;
			justify-content: space-between;

			.title-left {
				font-size: 32rpx;
				font-weight: bold;
			}

			.title-right {
				font-size: 28rpx;
				color: $uni-text-color-grey;
			}
		}

		.ul-topic {
			width: 100%;
			padding: 0 0 30rpx;
			// padding: 10rpx 0;

			.li-topic {
				position: relative;
				// padding: 10rpx;
				// margin-bottom: 30rpx;
				width: 100%;
				display: flex;
				align-items: center;
				// justify-content: space-between;

				.topic-img {
					position: absolute;
					top: 0;
					left: 0;
					width: 100%;
					// width: 140rpx;
					height: 160rpx;
					z-index: -1;

					image {
						width: 100%;
						height: 100%;
					}
				}

				.topic-desc {
					padding: 0 60rpx;
					width: 100%;
					// padding-left: 10rpx;
					display: flex;
					align-items: center;
					// flex-flow: column; //垂直排列
					justify-content: space-between; //两端对齐
					height: 160rpx;
					background-color: rgba(0, 0, 0, .4);

					.desc-title {
						position: absolute;
						top: 50%;
						left: 35px;
						// padding-bottom: 10rpx;
						font-size: 44rpx;
						font-weight: bold;
						color: #fff;
					}

					.desc-exp {
						position: absolute;
						top: 43%;
						right: 15px;
						letter-spacing: 2rpx;
						line-height: 40rpx;
						font-size: 24rpx;
						color: #f5f5f5;
					}
				}

				.topic-butt {
					flex-grow: 1;

					// text-align: right;
					.butt-style {
						width: 126rpx;
						height: 64rpx;
						line-height: 64rpx;
						// margin: 0 auto;
						margin-left: auto;
						text-align: center;
						font-size: 32rpx;
						// color: $uni-color-primary;
						color: #fff;
						// border: 1px solid $uni-color-primary;
						background-color: $uni-color-primary;
						border-radius: 10rpx;
					}
				}
			}
		}

		.trending-list {
			width: 100%;
			// padding-top: 20rpx;

			.news-box {
				width: 100%;
				margin-bottom: 60rpx;
				padding: 10rpx;
			}

			.news-img {
				width: 100%;
				height: 366rpx;

				image {
					width: 100%;
					height: 100%;
				}
			}


			.news-writing {
				width: 100%;
				padding-top: 10rpx;

				.p-location {
					font-size: 28rpx;
					color: $uni-text-color-grey;
				}

				.p-title {
					padding: 15rpx 0 10rpx 0;
					font-size: 32rpx;
					color: #000;
				}

				.p-come {
					width: 100%;
					display: flex;
					align-items: center;
					justify-content: space-between;
				}

				.p-come-left {
					display: flex;
					align-items: center;
				}

				.p-person {
					display: flex;
					align-items: center;
					margin-right: 20rpx;
				}


				.person-icon {
					display: block;
					width: 40rpx;
					height: 40rpx;
					// background-color: #000;
					border-radius: 50%;
					margin-right: 5rpx;
					image{
						border: 1px solid #f0f0f0;
						width: 100%;
						height: 100%;
						border-radius: 50%;
					}
				}

				.person {
					padding-left: 5rpx;
					font-size: 28rpx;
					color: #4e4b46;
					font-weight: bold;
				}

				.p-time {
					padding-left: 10rpx;
					font-size: 24rpx;
					color: $uni-text-color-grey;
				}

				.p-come-right {
					width: 40rpx;
					height: 40rpx;
					background-image: url("@/static/image/more.png");
					background-repeat: no-repeat;
					background-size: 100%;
				}
			}

		}
	}
</style>